package com.bianguo.android.functiondemo.bio;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.Scanner;

public class BioClient implements Runnable {

    private String host;
    private int port;

    private Charset charset;

    public BioClient(String host, int port) {
        super();
        this.host = host;
        this.port = port;
        charset = Charset.forName("UTF-8");
    }

    @Override
    public void run() {
        try {
            Socket mSocket = new Socket(host, port);
            OutputStream os = mSocket.getOutputStream();
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入: ");
            String line = scanner.nextLine();
            os.write(line.getBytes(charset));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        BioClient client = new BioClient("localhost", 9200);
        new Thread(client).start();
    }
}
